package com.ruoyi.tcsp.controller;

import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.tcsp.domain.bean.req.ScientificInfoReq;
import com.ruoyi.tcsp.domain.mysql.ScientificBaseInfo;
import com.ruoyi.tcsp.service.ScientificInfoService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;

import java.util.List;

/**
 * 科技成果Controller
 * 
 * @author Rwt
 * @date 2025-04-10
 */
@RestController
@RequestMapping("/tcsp/scientificInfo")
public class TcspScientificBaseInfoController extends BaseController
{
    @Autowired
    private ScientificInfoService scientificInfoService;
    /**
     * 查询科技成果列表selectScientificBaseInfoByScientificId
     */
    @PreAuthorize("@ss.hasPermi('tcsp:scientificInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(ScientificBaseInfo tcspScientificBaseInfo)
    {
        startPage();
        List<ScientificBaseInfo> list =
                scientificInfoService.selectScientificBaseInfoList(tcspScientificBaseInfo);
        return getDataTable(list);
    }

    /**
     * 导出科技成果列表
     */
    @PreAuthorize("@ss.hasPermi('tcsp:scientificInfo:export')")
    @Log(title = "科技成果", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScientificBaseInfo tcspScientificBaseInfo)
    {
        List<ScientificBaseInfo> list = scientificInfoService.selectScientificBaseInfoList(tcspScientificBaseInfo);
        ExcelUtil<ScientificBaseInfo> util = new ExcelUtil<ScientificBaseInfo>(ScientificBaseInfo.class);
        util.exportExcel(response, list, "科技成果数据");
    }

    /**
     * 获取科技成果详细信息
     */
    @PreAuthorize("@ss.hasPermi('tcsp:scientificInfo:query')")
    @GetMapping(value = "/{scientificId}")
    public AjaxResult getInfo(@PathVariable("scientificId") Long scientificId)
    {
        return success(scientificInfoService.selectScientificBaseInfoByScientificId(scientificId));
    }

    /**
     * 新增科技成果
     */
    @PreAuthorize("@ss.hasPermi('tcsp:scientificInfo:add')")
    @Log(title = "科技成果", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScientificInfoReq scientificInfoReq)
    {
        LoginUser loginUser = getLoginUser();
        int res = scientificInfoService.insertScientificBaseInfo(scientificInfoReq, loginUser);
        return toAjax(res);
    }

    /**
     * 修改科技成果
     */
    @PreAuthorize("@ss.hasPermi('tcsp:scientificInfo:edit')")
    @Log(title = "科技成果", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScientificInfoReq req)
    {
        LoginUser loginUser = getLoginUser();
        int res = scientificInfoService.updateScientificBaseInfo(req, loginUser);
        return toAjax(res);
    }

    /**
     * 删除科技成果
     */
    @PreAuthorize("@ss.hasPermi('tcsp:scientificInfo:remove')")
    @Log(title = "科技成果", businessType = BusinessType.DELETE)
	@DeleteMapping("/{scientificIds}")
    public AjaxResult remove(@PathVariable Long[] scientificIds)
    {
        return toAjax(scientificInfoService.deleteScientificBaseInfoByScientificIds(scientificIds));
    }
}
